package com.example.demo.controller;

import com.example.demo.pojo.PublicFields;
import com.example.demo.pojo.Result;
import com.example.demo.pojo.dto.ComponentDTO;
import com.example.demo.pojo.dto.InboundDTO;
import com.example.demo.pojo.dto.InventoryDTO;
import com.example.demo.pojo.entity.Inventory;
import com.example.demo.pojo.query.ComponentQuery;
import com.example.demo.pojo.query.InventoryQuery;
import com.example.demo.pojo.vo.ComponentVO;
import com.example.demo.pojo.vo.InventoryVO;
import com.example.demo.pojo.vo.PageVO;
import com.example.demo.service.IInventoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/inventory")
@Api(tags = "物资与厂库关联")
@RequiredArgsConstructor
@CrossOrigin(origins = {"http://localhost:8080"}, allowCredentials = "true")
public class InventoryController {
    private final IInventoryService inventoryService;
    @ApiOperation("绑定厂库")
    @PostMapping("/add")
    public Result addComponent(@RequestBody InventoryDTO inventoryDTO) {

        inventoryService.addStorage(inventoryDTO, PublicFields.newInstance());

        return Result.success("新增成功");
    }

    @ApiOperation("批量删除联系")
    @PostMapping("/delete")
    public Result deleteDevice(@RequestBody List<Long> ids){

        inventoryService.deleteInventory(ids);

        return Result.success("删除成功");
    }

    @ApiOperation("分页查询")
    @PostMapping("/page")
    public Result<PageVO<InventoryVO>> page(InventoryQuery inventoryQuery){

        return Result.success(inventoryService.queryInventoryPage(inventoryQuery));
    }

    @ApiOperation("修改信息")
    @PostMapping("/update")
    public Result updateDevice(@RequestBody InventoryDTO inventoryDTO){

        inventoryService.updateInventory(inventoryDTO, PublicFields.newInstance());

        return Result.success("修改成功");
    }
}
